package com.atguigu.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @title: MyRedissonConfig
 * @Author syh
 * @Date: 2022/6/27 21:00
 * @Version 1.0
 */

@Configuration
public class MyRedissonConfig {

    /**
     * 所有对Redisson的使用都是通过RedissonClient对象
     *
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        // 1.创建实例
        Config config = new Config();
//        config.useSingleServer().setAddress("redis://192.168.0.108:6379");// 家里redis地址
        config.useSingleServer().setAddress("redis://192.168.140.243:6379");// 手机热点redis地址
        // 2. 根据config创建出RedissonClient实例
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
